#include "Node.h"
#include "NodeImpl.h"

namespace wsbus {


	Node::Node(int appId, const std::string &host, const std::string &port)
		: impl_(new NodeImpl(appId, host, port))
	{

	}

	Node::~Node()
	{
		delete impl_;
	}

	void Node::setAuth(const std::string &username, const std::string &password)
	{
		return impl_->setAuth(username, password);
	}

	void Node::start()
	{
		return impl_->start();
	}

	PackagePtr Node::newRequestPackage(const MessagePtr &msg, int toAppType, int toSessionId)
	{
		return impl_->newRequestPackage(msg, toAppType, toSessionId);
	}

	PackagePtr Node::newRequestPackage(const std::string &command, const std::string &data, int toAppType, int toSessionId)
	{
		return impl_->newRequestPackage(command, data, toAppType, toSessionId);
	}

	int Node::sendMessage(const PackagePtr &reqMsg, PackagePtr &rspMsg, int msTimeout)
	{
		return impl_->sendMessage(reqMsg, rspMsg, msTimeout);
	}

	int Node::postMessage(const PackagePtr &msg, const HandleMessage &cb, int msTimeout)
	{
		return impl_->postMessage(msg, cb, msTimeout);
	}

	int Node::pushMessage(const MessagePtr &msg)
	{
		return impl_->pushMessage(msg);
	}

	int Node::replyMessage(const PackagePtr &reqMsg, const MoreMessagePtr &rspMsg)
	{
		return impl_->replyMessage(reqMsg, rspMsg);
	}

	void Node::addRequestHandler(const std::string &cmd, const std::function<MoreMessagePtr(const PackagePtr&)> &cb)
	{
		return impl_->addRequestHandler(cmd, cb);
	}

	void Node::addPublishHandler(const std::string &cmd, const std::function<void(const PackagePtr)> &cb)
	{
		return impl_->addPublishHandler(cmd, cb);
	}

	void Node::setStatusChangedHandler(const std::function<void(int status)> &cb)
	{
		return impl_->setStatusChangedHandler(cb);
	}

}